package com.example.eazytransfer.ui;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class HelloController implements Initializable {
    @FXML
    private Label labelCreateConnect;
    @FXML
    private Label labelSendFile;
    @FXML
    private Label labelReceiveFile;
    @FXML
    private Label labelAbout;

    @FXML
    private Pane paneMain;

    private Pane onCreateConnectPane, onSendFilePane, onReceiveFilePane, onAboutPane;

    @FXML
    protected void onCreateConnect() throws IOException {
        labelCreateConnect.setBackground(new Background(new BackgroundFill(Color.valueOf("#F1F1F1"), null, null)));
        labelSendFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelReceiveFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelAbout.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        if (onCreateConnectPane == null) {
            Parent parent = FXMLLoader.load(getClass().getResource("create-connect.fxml"));
            onCreateConnectPane = new Pane(parent);
        }
        paneMain.getChildren().clear();
        paneMain.getChildren().add(onCreateConnectPane);
    }

    @FXML
    protected void onSendFile() throws IOException {
        labelCreateConnect.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelSendFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#F1F1F1"), null, null)));
        labelReceiveFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelAbout.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        if (onSendFilePane == null) {
            Parent parent = FXMLLoader.load(getClass().getResource("send-file.fxml"));
            onSendFilePane = new Pane(parent);
        }
        paneMain.getChildren().clear();
        paneMain.getChildren().add(onSendFilePane);
    }

    @FXML
    protected void onReceiveFile() throws IOException {
        labelCreateConnect.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelSendFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelReceiveFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#F1F1F1"), null, null)));
        labelAbout.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        if (onReceiveFilePane == null) {
            Parent parent = FXMLLoader.load(getClass().getResource("receive-file.fxml"));
            onReceiveFilePane = new Pane(parent);
        }
        paneMain.getChildren().clear();
        paneMain.getChildren().add(onReceiveFilePane);
    }

    @FXML
    protected void onAbout() throws IOException {
        labelCreateConnect.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelSendFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelReceiveFile.setBackground(new Background(new BackgroundFill(Color.valueOf("#D9D9D9"), null, null)));
        labelAbout.setBackground(new Background(new BackgroundFill(Color.valueOf("#F1F1F1"), null, null)));
        if (onAboutPane == null) {
            Parent parent = FXMLLoader.load(getClass().getResource("about.fxml"));
            onAboutPane = new Pane(parent);
        }
        paneMain.getChildren().clear();
        paneMain.getChildren().add(onAboutPane);
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        try {
            onCreateConnect();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}